package net.bwie.jtp.controller;

import com.alibaba.fastjson.JSON;
import net.bwie.jtp.bean.TrafficChannelAvgBean;
import net.bwie.jtp.bean.TrafficChannelPvBean;
import net.bwie.jtp.bean.TrafficChannelUvBean;
import net.bwie.jtp.service.TrafficChannelStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 简介说明:
 *
 * @author: LiLi
 * @date: 2025/05/21 14:49:14
 * @version: 1.0
 */
@RestController
@RequestMapping("jtp/traffic")
public class TrafficController {

    @Autowired
    private TrafficChannelStateService trafficChannelStateService;

    private static final String DATE_DEFAULT_VALUE = "1970-07-01";
//  1 页面浏览请求拦截方法

    @RequestMapping("PvCount")
    public String GetPvCount(@RequestParam(value = "date", defaultValue = DATE_DEFAULT_VALUE) String date) {

        List<TrafficChannelPvBean> trafficPvReportList = trafficChannelStateService.getPvCount(date);

        if (null == trafficPvReportList || trafficPvReportList.isEmpty()){
            return "[]";
        }
//        System.out.println(trafficUvReportList);
        return JSON.toJSONString(trafficPvReportList);
    }
    //  2 唯一访客数请求拦截方法
    @RequestMapping("uvCount")
    public String GetUvCount(@RequestParam(value = "date", defaultValue = DATE_DEFAULT_VALUE) String date) {

        List<TrafficChannelUvBean> trafficUvReportList = trafficChannelStateService.getUvCount(date);

        if (null == trafficUvReportList || trafficUvReportList.isEmpty()){
            return "[]";
        }
//        System.out.println(trafficUvReportList);
        return JSON.toJSONString(trafficUvReportList);
    }

    //  3 平均会话时长（毫秒/会话）
    @RequestMapping("avg_session_duration")
    public String GetAvgSessionDuration(@RequestParam(value = "date", defaultValue = DATE_DEFAULT_VALUE) String date) {

        List<TrafficChannelAvgBean> avgCount = trafficChannelStateService.getAvgCount(date);

        if (null == avgCount || avgCount.isEmpty()){
            return "[]";
        }
//        System.out.println(trafficUvReportList);
        return JSON.toJSONString(avgCount);
    }


}
